package UIComponents
{
	import Classes.GameUtils.GU_filters;
	import Classes.GameUtils.MyTipSprite;
	import Classes.GameUtils.ToolTip_Sprite;
	
	import MyComponent.MyButton;
	
	import fl.events.ComponentEvent;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	public class ExpandWall extends Sprite
	{
		private var _oldLen:TextField;
		private var _newLen:TextField;
		private var _txt_ob:TextField;
		private var _playLv:TextField;
		private var _bulidLv:TextField;
		private var _txt_friend:TextField;
		private var _playLv1:TextField;
		private var _bulidLv1:TextField;
		private var _txt_Jb:TextField;
		private var _playLv2:TextField;
		private var _bulidLv2:TextField;
		public var _obkj:MyButton;
		public var _friendkj:MyButton;
		public var _jbkj:MyButton;
		
		private var obIc:DisplayObjectContainer;
		public function ExpandWall()
		{
			init();
		}
		
		private function init():void
		{
			this._oldLen=this.getChildByName("oldLen") as TextField;
			this._newLen=this.getChildByName("newLen") as TextField;
			this._txt_ob=this.getChildByName("txt_ob") as TextField;
			this._playLv=this.getChildByName("playLv") as TextField;
			this._bulidLv=this.getChildByName("bulidLv") as TextField;
			this._txt_friend=this.getChildByName("txt_friend") as TextField;
			this._playLv1=this.getChildByName("playLv1") as TextField;
			
			this._bulidLv1=this.getChildByName("bulidLv1") as TextField;
			this._txt_Jb=this.getChildByName("txt_Jb") as TextField;
			this._playLv2=this.getChildByName("playLv2") as TextField;
			this._bulidLv2=this.getChildByName("bulidLv2") as TextField;
			this._obkj=this.getChildByName("obkj") as MyButton;
			this._friendkj=this.getChildByName("friendkj") as MyButton;
			this._jbkj=this.getChildByName("jbkj") as MyButton;
			
			this.obIc=this.getChildByName("ob") as DisplayObjectContainer;
			
			this.controlMoenyIcon(FlatInfo.isOPenQQVip);
			
			//保存旧的颜色
			bulidLvColor	=	this._bulidLv.textColor;
			playLvColor		=	this._playLv1.textColor;
			friendColor		=	this._txt_friend.textColor;
			jbColor			=	this._txt_Jb.textColor;
			obColor 		=	this._txt_ob.textColor;
			
			
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("jbStyle"),new MyTipSprite("用银币开地"),ToolTip_Sprite.DIRECTION_LEFT);
			var tt:String=FlatInfo.isOPenQQVip==true?"需求施工车":"用金币开地";
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("obStyle"),new MyTipSprite(tt),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("friendStyle"),new MyTipSprite("用好友开地"),ToolTip_Sprite.DIRECTION_LEFT);
//			var tt2:String=FlatInfo.isOPenQQVip==true?"需求施工车":"需求金币";
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("ob"),new MyTipSprite("需求金币"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("sgc"),new MyTipSprite("需求施工车"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("jb"),new MyTipSprite("需求银币"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("lv1"),new MyTipSprite("需求用户等级"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("houseLv1"),new MyTipSprite("需求避难所基地等级"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("fIcon"),new MyTipSprite("给力好友：不低于玩家等级一半的好友为给力好友"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("lv2"),new MyTipSprite("需求用户等级"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("houseLv2"),new MyTipSprite("需求避难所基地等级"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("lv3"),new MyTipSprite("需求用户等级"),ToolTip_Sprite.DIRECTION_LEFT);
			ToolTip_Sprite.getInstance().setTip(this.getChildByName("houseLv3"),new MyTipSprite("需求避难所基地等级"),ToolTip_Sprite.DIRECTION_LEFT);
			
			addLister();
		}
		public function controlMoenyIcon(qb:Boolean=true):void
		{
			this.obIc.getChildByName("qdian").visible=false;
			this.obIc.getChildByName("obIcon").visible=!qb;
			this.getChildByName("sgc").visible=qb;
		}
		
		private var havenWall:IHavenWall;
		public function setExpandWall(iwall:IHavenWall):void
		{
			this.havenWall=iwall;
			this._bulidLv.text=this._bulidLv1.text=this._bulidLv2.text= havenWall.havenLv.toString() + "/" + this.havenWall.houseBuildingLv.toString();
			this._newLen.text=this.havenWall.newWallW+"x"+this.havenWall.newWallH;
			this._oldLen.text=this.havenWall.oldWallW+"x"+this.havenWall.oldWallH;
			this._playLv.text=this._playLv1.text=this._playLv2.text= havenWall.playerLv.toString() +"/"+ this.havenWall.landGreade.toString();
			this._txt_friend.text= havenWall.friendNumByLv.toString() + "/" + this.havenWall.landFriendNum.toString();
			this._txt_Jb.text=	havenWall.money.toString() + "/" + this.havenWall.landNeedMoney.toString();
			this._txt_ob.text=	havenWall.gold.toString() + "/" + this.havenWall.landNeedOMoney.toString();
			
			this.setBtnGrey();
		}
		
		private function addLister():void
		{
			this._obkj.addEventListener(ComponentEvent.BUTTON_DOWN,ObExpendFun);
			this._friendkj.addEventListener(ComponentEvent.BUTTON_DOWN,friendExpendFun);
			this._jbkj.addEventListener(ComponentEvent.BUTTON_DOWN,JbExpendFun);
		}
		
		private function ObExpendFun(e:ComponentEvent):void
		{
			this.havenWall.expendLandFun(1);
		}
		
		private function friendExpendFun(e:ComponentEvent):void
		{
			this.havenWall.expendLandFun(2);
		}
		
		private function JbExpendFun(e:ComponentEvent):void
		{
			this.havenWall.expendLandFun(3);
		}
		
		private function setBtnGrey():void
		{
			
//			if(!havenWall.isReachOMoney() || !havenWall.isReachUserLv() || !havenWall.isReachMainHouseLv())
			if(havenWall.gold<havenWall.landNeedOMoney  || havenWall.playerLv<havenWall.landGreade  || havenWall.havenLv<havenWall.houseBuildingLv)
			{
				this._obkj.filters	=	[GU_filters.grayfilter];
				this._obkj.mouseEnabled = this._obkj.mouseChildren = false;
			}
			else
			{
				this._obkj.filters	=	null;
				this._obkj.mouseEnabled = this._obkj.mouseChildren = true;
			}
			
			if(havenWall.friendNumByLv<havenWall.landFriendNum || havenWall.playerLv<havenWall.landGreade  || havenWall.havenLv<havenWall.houseBuildingLv)
			{
				this._friendkj.filters	=	[GU_filters.grayfilter];
				this._friendkj.mouseEnabled = this._friendkj.mouseChildren = false;
			}
			else{ 
				this._friendkj.filters	=	null;
				this._friendkj.mouseEnabled = this._friendkj.mouseChildren = true;
			}
			
			if(havenWall.money<havenWall.landNeedMoney || havenWall.playerLv<havenWall.landGreade  || havenWall.havenLv<havenWall.houseBuildingLv)
			{
				this._jbkj.filters	=	[GU_filters.grayfilter];
				this._jbkj.mouseEnabled = this._jbkj.mouseChildren = false;
			}
			else{
				this._jbkj.filters	=	null;
				this._jbkj.mouseEnabled = this._jbkj.mouseChildren = true;
			}
//			this._bulidLv.textColor=this._bulidLv1.textColor=this._bulidLv2.textColor = havenWall.isReachMainHouseLv()?this.bulidLvColor:0xff0000;
//			this._playLv.textColor=this._playLv1.textColor=this._playLv2.textColor= havenWall.isReachUserLv()?this.playLvColor:0xff0000;
//			this._txt_friend.textColor = havenWall.isReachFriendNum()?this.friendColor:0xff0000;
//			this._txt_Jb.textColor =	havenWall.isReachMoney()?this.jbColor:0xff0000;
//			this._txt_ob.textColor =	havenWall.isReachOMoney()?this.obColor:0xff0000;
			this._bulidLv.textColor=this._bulidLv1.textColor=this._bulidLv2.textColor = havenWall.havenLv>=havenWall.houseBuildingLv?0x00ff00:0xff0000;
			this._playLv.textColor=this._playLv1.textColor=this._playLv2.textColor= havenWall.playerLv>=havenWall.landGreade?0x00ff00:0xff0000;
			this._txt_friend.textColor = havenWall.friendNumByLv>=havenWall.landFriendNum?0x00ff00:0xff0000;
			this._txt_Jb.textColor =	havenWall.money>=havenWall.landNeedMoney?0x00ff00:0xff0000;
			this._txt_ob.textColor =	havenWall.gold>=havenWall.landNeedOMoney?0x00ff00:0xff0000;
		}
		
		private var bulidLvColor:uint;
		private var playLvColor:uint;
		private var friendColor:uint;
		private var jbColor:uint;
		private var obColor:uint;
	}
}